home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / html / ibfcode.js next >
Encoding:
Text File  |  2002-06-12  |  4.0 KB  |  190 lines

  1. bbtags   = new Array();
  2.  
  3. //--------------------------------------------
  4. // Get stack size
  5. //--------------------------------------------
  6.  
  7. function stacksize(thearray)
  8. {
  9.     for (i = 0 ; i < thearray.length; i++ )
  10.     {
  11.         if ( (thearray[i] == "") || (thearray[i] == null) || (thearray == 'undefined') )
  12.         {
  13.             return i;
  14.         }
  15.     }
  16.     
  17.     return thearray.length;
  18. }
  19.  
  20. //--------------------------------------------
  21. // Push stack
  22. //--------------------------------------------
  23.  
  24. function pushstack(thearray, newval)
  25. {
  26.     arraysize = stacksize(thearray);
  27.     thearray[arraysize] = newval;
  28. }
  29.  
  30. //--------------------------------------------
  31. // Pop stack
  32. //--------------------------------------------
  33.  
  34. function popstack(thearray)
  35. {
  36.     arraysize = stacksize(thearray);
  37.     theval = thearray[arraysize - 1];
  38.     delete thearray[arraysize - 1];
  39.     return theval;
  40. }
  41.  
  42. //--------------------------------------------
  43. // Close current open tag
  44. //--------------------------------------------
  45.  
  46. function closelast()
  47. {
  48.  
  49.     if (bbtags[0])
  50.     {
  51.         document.REPLIER.Post.value += "[/" + popstack(bbtags) + "]";
  52.     }
  53.     
  54.     document.REPLIER.Post.focus();
  55.     
  56. }
  57.  
  58. //--------------------------------------------
  59. // Close all tags
  60. //--------------------------------------------
  61.  
  62. function closeall()
  63. {
  64.     if (bbtags[0])
  65.     {
  66.         while (bbtags[0])
  67.         {
  68.             document.REPLIER.Post.value += "[/" + popstack(bbtags) + "]";
  69.         }
  70.         
  71.         document.REPLIER.Post.value += " ";
  72.     }
  73.     
  74.     document.REPLIER.Post.focus();
  75. }
  76.  
  77. //--------------------------------------------
  78. // EMOTICONS
  79. //--------------------------------------------
  80.  
  81. function emoticon(theSmilie)
  82.     {
  83.     if (document.REPLIER.Post.caretPos && document.REPLIER.Post.createTextRange)
  84.     {
  85.         var caretPos = document.REPLIER.Post.caretPos;
  86.         caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? theSmilie + ' ' : theSmilie;
  87.     }
  88.     else
  89.     {
  90.         document.REPLIER.Post.value += ' ' + theSmilie + ' ';
  91.     }
  92.     
  93.     document.REPLIER.Post.focus();
  94. }
  95.  
  96. //--------------------------------------------
  97. // ADD CODE
  98. //--------------------------------------------
  99.  
  100. function add_code(NewCode)
  101. {
  102.     document.REPLIER.Post.value += NewCode;
  103.     document.REPLIER.Post.focus();
  104.     return;
  105. }
  106.  
  107. //--------------------------------------------
  108. // ALTER FONT
  109. //--------------------------------------------
  110.  
  111. function alterfont(theval, thetag)
  112. {
  113.     if (theval == 0)
  114.     {
  115.         return;
  116.     }
  117.     else
  118.     {
  119.         document.REPLIER.Post.value += "[" + thetag + "=" + theval + "]";
  120.         pushstack(bbtags, thetag);
  121.     }
  122.     
  123.     document.REPLIER.ffont.selectedIndex  = 0;
  124.     document.REPLIER.fsize.selectedIndex  = 0;
  125.     document.REPLIER.fcolor.selectedIndex = 0;
  126.     
  127.     document.REPLIER.Post.focus();
  128. }
  129.  
  130.  
  131. //--------------------------------------------
  132. // SIMPLE TAGS (such as B, I U, etc)
  133. //--------------------------------------------
  134.  
  135. function simpletag(thetag)
  136. {
  137.     document.REPLIER.Post.value += "[" + thetag + "]";
  138.     
  139.     pushstack(bbtags, thetag);
  140.     
  141.     document.REPLIER.Post.focus();
  142. }
  143.  
  144. function tag_url()
  145. {
  146.     var FoundErrors = '';
  147.     var enterURL   = prompt(text_enter_url, "http://");
  148.     var enterTITLE = prompt(text_enter_url_name, "My Webpage");
  149.     if (!enterURL)
  150.     {
  151.         FoundErrors += " " + error_no_url;
  152.     }
  153.     if (!enterTITLE)
  154.     {
  155.         FoundErrors += " " + error_no_title;
  156.     }
  157.     if (FoundErrors)
  158.     {
  159.         alert("Error!"+FoundErrors);
  160.         return;
  161.     }
  162.     var ToAdd = "[URL="+enterURL+"]"+enterTITLE+"[/URL]";
  163.     document.REPLIER.Post.value+=ToAdd;
  164.     document.REPLIER.Post.focus();
  165. }
  166.  
  167. function tag_image()
  168. {
  169.     var FoundErrors = '';
  170.     var enterURL   = prompt(text_enter_image, "http://");
  171.     if (!enterURL) {
  172.         FoundErrors += " " + error_no_url;
  173.     }
  174.     if (FoundErrors) {
  175.         alert("Error!"+FoundErrors);
  176.         return;
  177.     }
  178.     var ToAdd = "[IMG]"+enterURL+"[/IMG]";
  179.     document.REPLIER.Post.value+=ToAdd;
  180.     document.REPLIER.Post.focus();
  181. }
  182.  
  183. function tag_email()
  184. {
  185.     var emailAddress = prompt(text_enter_email,"");
  186.     if (!emailAddress) { alert(error_no_email); return; }
  187.     var ToAdd = "[EMAIL]"+emailAddress+"[/EMAIL]";
  188.     document.REPLIER.Post.value+=ToAdd;
  189.     document.REPLIER.Post.focus();
  190. }